import http from '@/common/request.js'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */
let token = '';
const myToken = function (data) {
	token = data;
}

const baseUrl = http.config.rootUrl

/* 首页 */
const index = (data) => { return http.request({url: 'index/index', data })}

/* 新闻资讯 */
const newsIndex = (data) => { return http.request({url: 'news/index', data })}
const newsView = (data) => { return http.request({url: 'news/view', data })}

/* 签到 */
const signinIndex = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'user/signin/index', data })
}
const signinView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'user/signin/view', data })
}



/* 商品接口 */
const goodsIndex = (data) => { return http.request({url: 'goods/index', data })}
const goodsView = (data) => { return http.request({url: 'goods/view', data })}
const goodsCategory = (data) => { return http.request({url: 'goods/category', data })}
const goodsComment = (data) => { return http.request({url: 'goods/comment', data })}
const goodsRecommend = (data) => { return http.request({url: 'goods/recommend', data })}
const goodsKeyword = (data) => { return http.request({url: 'goods/keyword', data })}
const goodsPost = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'goods/post', data })
}




/* Combination */
const combinationIndex = (data) => { return http.request({url: 'combination/index', data })}
const combinationView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'combination/view', data })
}

/* Seckill */
const seckillIndex = (data) => { return http.request({url: 'seckill/index', data })}
const seckillView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'seckill/view', data })
}





/* Bargain */
const bargainIndex = (data) => { return http.request({url: 'bargain/index', data })}
const bargainView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'bargain/view', data })
}
const bargainUser = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'bargain/user', data })
}





/* User */
const userAuthorize = (data) => { return http.request({ url: 'user/wechat/login', data, method: 'POST' })}
const userCommonInfo = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/user/common', data, method: 'POST' })
}
const userIndex = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/user/index', data, method: 'POST' })
}
const userUpdate = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/user/update', data })
}
const userVip = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/user/vip', data })
}
const userCollect = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'user/user/collect', data })
}
const userCollection = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'user/user/collection', data })
}


/* Address */
const userAddressIndex = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/address/index', data })
}
const userAddressEdit = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/address/edit', data, method: 'POST' })
}
const userAddressDefault = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/address/setdefault', data, method: 'POST' })
}
const userAddressDelete = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/address/delete', data, method: 'POST' })
}
const userAddressView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/address/view', data, method: 'POST' })
}


/* Coupon */
const userCouponIndex = (data) => { return http.request({url: 'user/coupon/index', data })}
const userCouponView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({url: 'user/coupon/view', data })
}


/* Account */
const userAccountIndex = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/account/index', data })
}
const userAccountView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/account/view', data })
}
const userAccountIntegral = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'user/account/integral', data })
}


/* Distribution */
const distributionIndex= (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/index', data })
}
const distributionCard= (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/card', data })
}
const distributionStatistics = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/statistics', data })
}
const distributionCommission = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/commission', data })
}
const distributionOrder = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/order', data })
}
const distributionWithdraw = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'distribution/withdraw', data })
}





/* Order */
const orderIndex = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/index', data })
}
const orderConfirm = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/confirm', data })
}
const orderCreate = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/create', data })
}
const orderView = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/view', data })
}
const orderDelete = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/delete', data })
}
const orderCancel = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/cancel', data, method: 'POST' })
}
const orderPayResult = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/payresult', data, method: 'POST' })
}
const orderReceipt = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/receipt', data, method: 'POST' })
}
const orderAgain = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/again', data, method: "POST" })
}
const orderRefund = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/refund', data, method: "POST" })
}
const orderRefundList = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/refundlist', data, method: "POST" })
}
const orderLogistics = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/logistics', data, method: "POST" })
}
const orderComment = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'order/comment', data, method: "POST" })
}
/* Cart */
const cartCreate = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'cart/create', data, method: "POST" })
}
const cartDelete = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'cart/delete', data, method: "POST" })
}
const cartUpdate = (data) => {
	http.interceptor.request = (config) => { config.header = { "token": token }}
	return http.request({ url: 'cart/update', data, method: "POST" })
}

// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const test = (data) => {
	/* http.config.baseUrl = "http://localhost:8080/api/"
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		}
	} */
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....')
		//判断返回状态 执行相应操作
		return response;
	}
	return http.request({
		//baseUrl: 'https://unidemo.dcloud.net.cn/',
		url: 'ajax/echo/text?name=uni-app',
		dataType: 'json',
		data,
	})
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	myToken,
	index,
	baseUrl,
	goodsIndex,
	goodsView,
	goodsPost,
	goodsKeyword,
	goodsCategory,
	goodsComment,
	goodsRecommend,
	userCouponIndex,
	userCouponView,
	newsIndex,
	newsView,
	signinIndex,
	signinView,
	combinationIndex,
	combinationView,
	seckillIndex,
	seckillView,
	bargainIndex,
	bargainView,
	bargainUser,
	userAuthorize,
	userCommonInfo,
	userIndex,
	userUpdate,
	userVip,
	userAddressIndex,
	userAddressEdit,
	userAddressView,
	userAddressDefault,
	userAddressDelete,
	userCollect,
	userCollection,
	userAccountIndex,
	userAccountView,
	userAccountIntegral,
	distributionIndex,
	distributionCard,
	distributionStatistics,
	distributionCommission,
	distributionOrder,
	distributionWithdraw,
	orderIndex,
	orderConfirm,
	orderView,
	orderCreate,
	orderDelete,
	orderCancel,
	orderReceipt,
	orderPayResult,
	orderAgain,
	orderRefund,
	orderRefundList,
	orderLogistics,
	orderComment,
	cartCreate,
	cartUpdate,
	cartDelete,
}
